import { PropsWithChildren } from 'react'
import Taro, { useLaunch } from '@tarojs/taro'
import { getApiConfig } from '../config/api'

import './app.scss'

// 全局API配置
export const apiConfig = getApiConfig()

// 全局配置数据
export const appConfig = {
  data: null as any
}

function App({ children }: PropsWithChildren<any>) {
  useLaunch(async () => {
    console.log('App launched.')
    
    try {
      const res = await Taro.request({
        url: `${apiConfig.baseUrl}/api/info/basic`,
        method: 'GET'
      })
      
      if (res.statusCode === 200 && res.data) {
        appConfig.data = res.data
        console.log('App config loaded:', appConfig.data)
      } else {
        console.error('Failed to load app config:', res)
      }
    } catch (error) {
      console.error('Error loading app config:', error)
    }
  })

  // children 是将要会渲染的页面
  return children
}
  


export default App
